package logic.ships.frigate;

import logic.nodes.TeamNode;
import ai.AIController;

import com.jme.math.Vector3f;

public class FrigateController extends AIController {
	
	private static final long serialVersionUID = 1L;
	
	private Frigate frigate;
	
	public FrigateController(Frigate frigate) {
		super(frigate);
		this.frigate = frigate;
	}
	
	@Override
	protected void delayedUpdate(float time) {
		TeamNode target = frigate.getCurrentTarget();
		if(target != null) {
			float minDist = frigate.getAutoWeaponShipProps().getMinWeaponRange();
			
			Vector3f currentPos = frigate.getLocalTranslation();
			Vector3f targetPos = target.getLocalTranslation();
			
			if(currentPos.distance(targetPos) < minDist) frigate.getMoveForwardController().stop(true);
			else {
				frigate.getMoveForwardController().stop(false);
				rotateTo(targetPos, time / frigate.getMovableShipProperties().getTurnSpeed() * 0.2f, false);
			}
		} else frigate.getMoveForwardController().stop(true);
	}
}